/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.wj.school.app.ui.controller;

import cn.wj.school.app.cache.ClientCacheMap;
import cn.wj.school.app.dto.LogOutReqMsg;
import cn.wj.school.app.enums.SessionFactory;
import cn.wj.school.app.ui.view.StageView;
import cn.wj.school.cloud.dto.SyUserDTO;
import cn.wj.school.common.controller.ControlledStage;
import cn.wj.school.common.controller.StageController;
import cn.wj.school.common.enums.UiFactory;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.stage.Stage;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * @author lidapeng
 */
public class MainController implements ControlledStage {

    @FXML
    private Label userName;

    @FXML
    private Label time;

    /**
     * 获取当前的stage
     *
     * @return
     */
    @Override
    public Stage getMyStage() {
        StageController stageController = UiFactory.INSTANCE.getStageController();
        return stageController.getStageBy(StageView.id.MAIN_VIEW);
    }

    public void loginOut() {
        SyUserDTO userDTO = ClientCacheMap.getCurrentUser();
        LogOutReqMsg reqMsg = new LogOutReqMsg();
        reqMsg.setCard(userDTO.getCard());
        if (SessionFactory.INSTANCE.isConnectedSever()) {
            SessionFactory.INSTANCE.sendServerRequest(reqMsg);
        }
    }
}
